package com.sq.util.encrypt;

import java.math.BigInteger;

/**
 * @author sq
 *
 */
public class Xor {

    /**
     * 异或加密
     */
    public static String xorEncrypt(String str, String key) {
        BigInteger strbi = new BigInteger(str.getBytes());
        BigInteger keybi = new BigInteger(key.getBytes());
        BigInteger encryptbi = strbi.xor(keybi);

        return new String(encryptbi.toByteArray());
    }

    /**
     * 异或解密
     */
    public static String xorDecrypt(String encryptStr, String key) {
        BigInteger encryptbi = new BigInteger(encryptStr.getBytes());
        BigInteger keybi = new BigInteger(key.getBytes());
        BigInteger decryptbi = encryptbi.xor(keybi);
        return new String(decryptbi.toByteArray());
    }

}
